<extend name="Base/common"/>
<block name="css">

</block>
<block name="body">
    <header class="mui-bar mui-bar-nav dl_header">
        <a href="javascript:history.back();" id="close" class="iconfont icon-guanbi dl_closed"></a>
        <a href="{:U('Agent/login')}" class="dl_fast">直接登录</a>
    </header>
    <div class="mui-content" id="container_wrap">
        <div  style="display: -webkit-box;-webkit-box-orient: horizontal;-webkit-box-pack: center;overflow: hidden;">
            <img src="__PUBLIC__/Home/images/index/xglogo.png" class="img-responsive center-block logo"/>
        </div>
        <!--账号密码登录-->
        <form class="form-horizontal dl_form" id="form_one">
            <div class="form-group form-line-input" style="margin: 0px;">
                <input type="text" class="form-control" id="username" style="padding-left:40px;" placeholder="账户名" name="username">
                <label for="username" style="top:24px;"><i class="iconfont icon-user"></i></label>
                <span class="help-block"></span>
            </div>
            <div class="form-group form-line-input has-success" style="margin-top:10px;">
                <input type="password" class="form-control" id="password" style="padding-left:40px;" placeholder="密码" name="password">
                <label for="password" style="top:24px;"><i class="iconfont icon-mima"></i></label>
                <span class="help-block"></span>
            </div>
            <div class="form-group form-line-input" style="margin: 0px;">
                <input type="password" class="form-control" id="repassword" style="padding-left:40px;" placeholder="重复密码" name="repassword">
                <label for="repassword" style="top:24px;"><i class="iconfont icon-user"></i></label>
                <span class="help-block"></span>
            </div>
            <div class="form-group form-line-input has-success" style="margin-top:10px;">
                <input type="text" class="form-control" id="nickname" style="padding-left:40px;" placeholder="姓名" name="nickname">
                <label for="nickname" style="top:24px;"><i class="iconfont icon-mima"></i></label>
                <span class="help-block"></span>
            </div>
            <div class="form-group form-line-input has-success" style="margin-top:10px;">
                <input type="text" class="form-control" id="mobile" style="padding-left:40px;" placeholder="手机号" name="mobile">
                <label for="mobile" style="top:24px;"><i class="iconfont icon-mima"></i></label>
                <span class="help-block"></span>
            </div>
            <div class="form-group form-line-input has-success" style="margin-top:10px;">
                <select id="department" class="form-control edited" name="department">
                    <option value="">选择所属部门</option>
                    <volist name="department_info" id="vo">
                        <option value="{$vo.id}">{$vo.title}</option>
                    </volist>
                </select>
                <label for="department" style="top:24px;"></label>
                <span class="help-block"></span>
            </div>
            <a href="javascript:" id="register_btn" class="btn btn-mini btn-primary common_btn">注册</a>

        </form>

    </div>


</block>

<block name="script">
    <script>
        $(function(){
            $("#register_btn").click(function(){
                var submit = false;
                //表单验证
                $('form input').each(function(){
                    if($(this).val()==""){
                        $.dialog({
                            content : '信息不能为空',
                            title: "alert",
                            time : 1000
                        });
                        submit = false;
                        return false;
                    }else{
                        submit = true;
                    }
                });
                if(submit){
                    var     $password=$("input[name=password]").val(),
                            $repassword=$("input[name=repassword]").val(),
                            $username=$("input[name=username]").val(),
                            $mobile=$("input[name=mobile]").val();

                    var u_re = /^[a-zA-z]\w{3,15}$/;

                    if(!u_re.test($username)){
                        $.dialog({
                            content: '用户名格式错误！',
                            title: "alert",
                            time: 1000
                        });
                        return false;
                    }

                    if($password != $repassword){
                        $.dialog({
                            content: '密码和重复密码不一致！',
                            title: "alert",
                            time: 1000
                        });
                        return false;
                    }


                    var m_re = /^1\d{10}$/
                    if (!m_re.test($mobile)) {
                        $.dialog({
                            content: '手机号格式错误！',
                            title: "alert",
                            time: 1000
                        });
                        return false;
                    }

                    $.post('{:U("Agent/register")}', $("form").serialize(), function(data){
                        if(data.status){
                            $.dialog({
                                content : data.info,
                                title: "ok",
                                time : 1000
                            });
                            setTimeout(function () {
                                location.href = data.url
                            },1000);
                        }else{
                            $.dialog({
                                content : data.info,
                                title: "alert",
                                time : 1000
                            });
                        }
                    });

                }

            })


        });
    </script>
</block>